 package com.yangguo.code.generator.util;

     
     import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.alibaba.simpleimage.ImageRender;
import com.alibaba.simpleimage.render.DrawTextItem;
import com.alibaba.simpleimage.render.DrawTextParameter;
import com.alibaba.simpleimage.render.DrawTextRender;
import com.alibaba.simpleimage.render.FixDrawTextItem;
import com.alibaba.simpleimage.render.ReadRender;
import com.alibaba.simpleimage.render.WriteRender;

     public class ImageUtils {
         final static File        path              = new File("/Users/yangguo/Downloads/W020211231406812160557-2.jpg");
         final static File rpath = new File("/Users/yangguo/Downloads/W020211231406812160557-加水印.jpg");
         final static Font  FONT              = new Font("黑体", Font.PLAIN, 20);

         public static void main(String[] args) throws Exception {

              FixDrawTextItem item =
                  new FixDrawTextItem("静态停车", Color.RED, Color.RED,
                      FONT, 5, FixDrawTextItem.Position.TOP_LEFT, 1f);

              doDrawImageText(item);

         }


         public static void doDrawImageText(DrawTextItem... items) throws Exception {
             InputStream in = null;
             ImageRender fr = null;
             try {
                 in = new FileInputStream(path);
                 ImageRender rr = new ReadRender(in);

                 DrawTextParameter dp = new DrawTextParameter();

                 if (items != null) {
                     for (DrawTextItem itm : items) {
                         dp.addTextInfo(itm);
                     }
                 }
                 DrawTextRender dtr = new DrawTextRender(rr, dp);
                 fr = new WriteRender(dtr,rpath);
                 fr.render();
             } finally {
                 IOUtils.closeQuietly(in);
                 if (fr != null) {
                     fr.dispose();
                 }
             }
         }
     }


